import {getsongurlapi, getsongfinfoapi} from '../network/songlist'

export const playbar = {
  state:{
    //音乐url
    musicurl:null,
    //当前播放音乐ID
    musicplayid:null,
    //播放全部音乐ID
    musiclistall:[],
    //音乐信息
    songinfopalyer:null,

    //播放器变化图标
    playericon:'el-icon-video-play'
  },
  mutations: {

    //写入音乐url
    GETSONG(state, payload) {
      state.musicurl = payload.url;
      state.musicplayid = payload.id
    },
    //写入音乐播放器信息
    GETSONGINFO(state, payload) {
      state.songinfopalyer = payload
    },
    //播放音乐列表
    PLAYALL(state,payload) {
      //state.musiclistall = payload
      state.musicplayid = payload.id;
      state.musiclistall = payload.FtrackIds
    },

    //播放器变化图标-方法
    PLAYERICONSET(state, payload) {
      switch (payload) {
        case true:
          state.playericon = 'el-icon-video-pause'
          break;
      
        case false:
          state.playericon = 'el-icon-video-play'
          break;
      }
    },
  },
  actions: {
    //返回mutations音乐url
    async getsong(content, value) {
      await getsongurlapi(value).then(res => {
        let url = res.data.data[0].url
        content.commit('GETSONG',res.data.data[0])
        console.log(res.data.data[0]);
      }
     ),
     await getsongfinfoapi(value).then(res => {
        content.commit('GETSONGINFO',res.data)
        //console.log(res.data);
      })
    }
  },
  getters: {
    //返回当前播放音乐的索引
    musicindexof(state) {
      return state.musiclistall.indexOf(state.musicplayid)
    }
  }
}